<?php

 /**
  * @package JooS
  * @subpackage PHPackager_FS
  */

  class JooS_PHPackager_FS_Action {
    private $_callback;

    private $_args;

    /**
     * @param callback $callback
     * @param array $args
     */
    public function __construct($callback, $args = array()) {
      if (!is_callable($callback))
        self::throwException("FS_Action's parameter \$callback must be callable");
      if (!is_array($args))
        self::throwException("FS_Action's parameter \$args must be an array");

      $this->_callback = $callback;
      $this->_args = $args;
    }

    public function __invoke() {
      return call_user_func_array($this->_callback, $this->_args);
    }

    /**
     * @param string $Message
     * @param int $Code
     * @throws JooS_PHPackager_FS_Action_Exception
     */
    protected static function throwException($Message, $Code = 0) {
      require_once "JooS/PHPackager/FS/Action/Exception.php";

      throw new JooS_PHPackager_FS_Action_Exception($Message, $Code);
    }
  }
